<% layout('/layouts/default.html', {title: '单位管理', libs: ['validate']}){ %>
<div class="main-content">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">
                <i class="fa icon-grid"></i> ${text(office.isNewRecord ? '新增单位' : '编辑单位')}
            </div>
            <div class="box-tools pull-right">
                <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
            </div>
        </div>
        <#form:form id="inputForm" model="${office}" action="${ctx}/sys/office/save" method="post" class="form-horizontal">
        <div class="box-body">
            <div class="form-unit">${text('基本信息')}</div>
            <div class="row">
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4">${text('上级单位')}：</label>
                        <div class="col-sm-8">
                            <#form:treeselect id="parent" title="${text('上级单位')}"
                            path="parent.id" labelPath="parent.officeName"
                            url="${ctx}/sys/office/treeData?excludeCode=${office.id}&ctrlPermi=${@Global.getConfig('user.adminCtrlPermi', '2')}"
                            class="" allowClear="true" canSelectRoot="true" canSelectParent="true"/>
                        </div>
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required ">*</span> ${text('单位名称')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:input path="officeName" maxlength="100" class="form-control required "/>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row ">
                <div class="col-xs-6 hide">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required ">*</span> ${text('单位全称')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:input path="fullName" maxlength="200" class="form-control"/>
                        </div>
                    </div>
                </div>

                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required ">*</span> ${text('单位代码')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:hidden path="isNewRecord"/>
                            <#form:hidden path="officeCode"/>
                            <#form:input path="viewCode" maxlength="64" readonly="${!office.isNewRecord}" class="form-control required abc"/>
                        </div>
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required ">*</span> ${text('单位类型')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">

                            <#form:select path="extend.extendS1" dictType="sd_deliver_unit_type" blankOption="true" class="form-control required"

                            remote="${ctx}/sd/docDeliverRecord/checkUnitType?id="  onchange="send()" id="send1"
                            data-msg-remote="${text('此单位类型已存在')}"
                            />

                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-xs-6 hide">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required ">*</span> ${text('机构类型')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:select path="officeType" value="1" dictType="sys_office_type" class="form-control " />
                        </div>
                    </div>
                </div>

                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required ">*</span> ${text('排序号')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:input path="treeSort" maxlength="10" class="form-control required digits"/>


                        </div>
                    </div>
                </div>


            </div>

                 <!--   <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required ">*</span> ${text('是否拟办单位')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:select path="extend.extendS2" dictType="sd_deliver_unit" blankOption="true" class="form-control required"/>

                            </div>
                        </div>
                    </div>
            </div>-->
                     <!--   <div class="row">
                            <div class="col-xs-6">
                                <div class="form-group">
                                    <label class="control-label col-sm-4" title="">
                                        <span class="required ">*</span> ${text('是否归档单位')}：<i class="fa icon-question hide"></i></label>
                                    <div class="col-sm-8">
                                        <#form:select path="extend.extendS3" dictType="sd_archives_unit" blankOption="true" class="form-control required" />

                                    </div>
                                </div>
                            </div>-->
            <div class="row">
                                <div class="col-xs-6" id="chan">
                                    <div class="form-group">
                                        <label class="control-label col-sm-4" title="">
                                            <span class="required ">*</span> ${text('单位柜号')}：<i class="fa icon-question hide"></i></label>
                                        <div class="col-sm-8">
                                            <#form:input path="extend.extendS4"  class="form-control" id="edit"
                                            remote="${ctx}/sd/docDeliverRecord/check?email=" onkeyup="chang()"
                                            data-msg-remote="${text('此柜号已存在')}"/>
                                        </div>
                                    </div>
                </div>
            </div>
        <!--
            <div class="form-unit">${text('详细信息')}</div>
            <div class="row">
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required hide">*</span> ${text('负责人')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:input path="leader" maxlength="100" class="form-control "/>
                        </div>
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required hide">*</span> ${text('办公电话')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:input path="phone" maxlength="100" class="form-control phone"/>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required hide">*</span> ${text('联系地址')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:input path="address" maxlength="255" class="form-control "/>
                        </div>
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required hide">*</span> ${text('邮政编码')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:input path="zipCode" maxlength="100" class="form-control zipCode"/>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required hide">*</span> ${text('电子邮箱')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:input path="email" maxlength="300" class="form-control" />
                        </div>
                    </div>
                </div>
                <div class="col-xs-12">
                    <div class="form-group">
                        <label class="control-label col-sm-2" title="">
                            <span class="required hide">*</span> ${text('备注信息')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-10">
                            <#form:textarea path="remarks" rows="4" maxlength="500" class="form-control "/>
                        </div>
                    </div>
                </div>-->
            </div><!--<#form:extend collapsed="true" />-->
        </div>
        <div class="box-footer">
            <div class="row">
                <div class="col-sm-offset-2 col-sm-10">
                    <% if (hasPermi('sys:office:edit')){ %>
                    <button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> ${text('保 存')}</button>&nbsp;
                    <% } %>
                    <button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
                </div>
            </div>
        </div>
    </#form:form>
</div>
</div>
<% } %>
<script>
    function chang() {
        var send=document.getElementById("edit").value;
        var uri= document.getElementById("edit").getAttribute("remote");
        document.getElementById("edit").setAttribute("remote","${ctx}/sd/docDeliverRecord/check?email="+send);


    }
    function send(){
        var send=document.getElementById("send1").value;
             document.getElementById("send1").setAttribute("remote","${ctx}/sd/docDeliverRecord/checkUnitType?id="+send);
        if (send==1){
           document.getElementById("edit").removeAttribute("readonly");

            document.getElementById("edit").value=""
            document.getElementById("edit").setAttribute("remote","${ctx}/sd/docDeliverRecord/check?email=");
            $("#chan").css("display","block")
        }else{

            document.getElementById("edit").setAttribute("readonly","true");
            document.getElementById("edit").value="0"
            document.getElementById("edit").removeAttribute("remote");
           $("#chan").css("display","none")
        }
    }
    var ed;
    window.onload=function(){
        var is= '${text(office.isNewRecord )}'
        //console.log(is+" "+typeof(is))
        if(is=="true"){
            $("#chan").css("display","none")
            document.getElementById("edit").value="0"
        }else{

            if($("#edit").val()==="0"){
                $("#chan").css("display","none")
            }

        }


    }
    $("#inputForm").validate({
        submitHandler: function(form){
            js.ajaxSubmitForm($(form), function(data){
              //  alert($("#edit").val())
                if($("#edit").val()!='0' && $("#edit").val()==""){
                    js.layer.msg("输入柜号",{icon:5})
                    return false;
                }

                  js.showMessage(data.message);
                  if(data.result == Global.TRUE){
                      js.closeCurrentTabPage(function(contentWindow){
                          (contentWindow.win||contentWindow).$('#dataGrid').dataGrid('refreshTreeChildren',
                              $('#parentCode').val(), '${office.id}');
                      });
                  }
            }, "json");
        }
    });
    $('#officeName').change(function(){
        if ($('#fullName').val()==''){
            $('#fullName').val($(this).val());
        }
    });
    // 选择上级节点回调方法
    function treeselectCallback(id, act, index, layero){
        if (id == 'parent' && (act == 'ok' || act == 'clear')){
            // 创建并初始化下一个节点信息，如：排序号、默认值
            $.get('${ctx}/sys/office/createNextNode?parentCode='
                +$('#parentCode').val(), function(data){
                $('#treeSort').val(data.treeSort);
            });
        }
    }
</script>
